package com.zzw.hj51;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 输出单向链表中倒数第k个节点
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static class ListNode {
        public int val;
        public ListNode pNext;
    }

    public static ListNode findKthNodeToTail(ListNode head, int k) {
        int i = 0;
        while (head.pNext != null && i < k) {
            head = head.pNext;
            i++;
        }
        return head;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            ListNode head = new ListNode();
            head.pNext = null;
            // 头插法
            for (int i = 0; i < n; i++) {
                ListNode p = new ListNode();
                p.pNext = head.pNext;
                p.val = in.nextInt();
                head.pNext = p;
            }
            int k = in.nextInt();
            ListNode kNode = findKthNodeToTail(head, k);
            System.out.println(kNode.val);
        }
        in.close();
    }
}
